package com.example.mylibrary;

        import static android.content.ContentValues.TAG;
        import android.app.Instrumentation;
        import android.util.Log;
        import androidx.test.platform.app.InstrumentationRegistry;
        import androidx.test.uiautomator.By;
        import androidx.test.uiautomator.UiDevice;
        import androidx.test.uiautomator.UiObject2;

        import org.junit.Before;
        import org.junit.Test;

public class BarterReleasePage {
    public static UiDevice device;
    public static Instrumentation instrumentation;

    @Before
    public void first() throws InterruptedException {
        Log.i(TAG, "连接设备");
        instrumentation =
                InstrumentationRegistry.getInstrumentation();
        device = UiDevice.getInstance(instrumentation);
        int width = device.getDisplayWidth();
        int height = device.getDisplayHeight();
        device.pressHome();
        Thread.sleep(2000);
        device.swipe(width - 10, height / 2, 50, height / 2, 10);
        Thread.sleep(2000);
        UiObject2 barter = device.findObject(By.text("Barter"));
        barter.click();
        Thread.sleep(3000);
    }

    //    登录
    private void login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).setText("2019012514");
        Thread.sleep(100);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).click();
        Thread.sleep(1000);
    }

    @Test
    public void testRelease() throws InterruptedException {
        login();
        Thread.sleep(1000);
        device.click(200, 700);
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("android.widget.TextView")).click();
        Thread.sleep(1000);
        device.click(350, 900);
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("50");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("13231154989");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("高数笔记你值得拥有！");
        Thread.sleep(1000);

    }
}